<template>
    <div class="main_page">
    <div class="page_top_view">
      <div>
        <info-item :item="infoItem" />
        <distance-item @sendAction="clickSwitchDistance" />
      </div>
      <system-item :list="sysList" @systemAction="clickSystemAction" />
    </div>
    <div class="page_bottom_view">
      <message-item @sendAction="clickSwitchDistance" :list="[]"/>
      <public-item code="A" @detail="openDetail"/>
      <public-item code="B" @detail="openDetail"/>
      <public-item code="C" @detail="openDetail"/>
    </div>
    <ConsultDetail ref="detail" title=""/>
  </div>
</template>

<script>
import infoItem from "./mainItem/infoItem.vue";
import distanceItem from "./mainItem/distanceItem.vue";
import systemItem from "./mainItem/systemItem.vue";
import messageItem from "./mainItem/messageItem.vue";
import publicItem from "./mainItem/publicItem.vue";
import {getloginInfo} from "@/api/labdata/employee";
import ConsultDetail from  "@/views/consultation/content/details.vue"
export default {
  name: "mainPage",
  components: {
    infoItem,
    distanceItem,
    systemItem,
    messageItem,
    publicItem,
    ConsultDetail,
  },
  data() {
    return {
      /*
      infoItem: {
        date: new Date(),
        week: "周三",
        type: "工作日",
        name: "张嘉倪",
        unit: "实验室建设与管理处",
        lastLogin:,
        count: 100,
      },*/
      infoItem:{},
      sysList: [
        {
          list: [
            {
              name: "实验室基础信息",
              icon: require("@/assets/image/icon00.png"),
              url: '/labdata/orgnization',
              auth:'labdata:flowDefination:query',
            },
            {
              name: "实验室安全教育",
              icon: require("@/assets/image/icon01.png"),
              url: 'https://njuptlas.mh.chaoxing.com/',
              auth:'consultation:content:query',
            },
            {
              name: "实验室预约管理",
              icon: require("@/assets/image/icon02.png"),
              url: '/labReservation/reservation',
              auth:'labdata:reservation:query',
            },
            {
              name: "实验室危险源管理",
              icon: require("@/assets/image/icon03.png"),
              url: '/labdanger/purchase',
              auth:'labdanger:purchase:query',
            },
            {
              name: "实验室安全检查",
              icon: require("@/assets/image/icon04.png"),
              url: '/labsafety/labsafety',
              auth:'labsafety:labsafetyForm:query',
            },
            {
              name: "实验室课程管理",
              icon: require("@/assets/image/icon05.png"),
              url: '/course/course',
              auth:'course:timetable:query',
            },
            {
              name: "实验室项目管理",
              icon: require("@/assets/image/icon06.png"),
              url: '/labbase/project_creation',
              auth:'labbase:project_creation:query',
            },
            {
              name: "实验室统计分析",
              cont: "(高基表)",
              icon: require("@/assets/image/icon07.png"),
              url: '',
              auth:'',
            },
          ],
        },
        {
          list: [
            {
              name: "实验室大数据展示",
              icon: require("@/assets/image/icon08.png"),
              url: '',
              auth:'',
            },
            {
              name: "实验室组织管理",
              icon: require("@/assets/image/icon09.png"),
              url: '/labdata/orgnization',
              auth:'labdata:orgnization:query',
            },
            {
              name: "实验室仪器与设备",
              icon: require("@/assets/image/icon10.png"),
              url: '/labdata/products',
              auth:'labbase:instrumentation:query',
            },
            {
              name: "实验室料单与维修",
              icon: require("@/assets/image/icon11.png"),
              url: '/labdata/receipt_form',
              auth:'labbase:receipt_form:query',
            },
          ],
        },
      ],
    };
  },
  created() {
    getloginInfo().then(response =>{
      this.infoItem = response.data;
    });
  },
  methods: {
    //点击切换待办流程
    clickSwitchDistance(e) {
    },
    //点击系统功能事件
    clickSystemAction(e) {
      //path需要跳转的路由
      let routePath = e.item.url;
      if(e.item.url == '' || !this.isPermit(e.item.auth)){
        routePath = '/';
      }
      if(routePath.indexOf("http")>=0){
        window.open(routePath, '_blank');
      }else{
        this.$emit('switchNavigation', {type: false})
        this.$router.push({ path: routePath || "/" });
      }

    },
    openDetail(item){
      this.$refs["detail"].openDetail(item.consultationId);
    },
    isPermit(permitKey){
      if(this.$store.state.user.name=='admin'){
        return true;
      }
      let  permissions = this.$store.getters.permissions;
      return permissions.includes(permitKey);
    },
  },
};
</script>

<style lang="scss" scoped>
.main_page {
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 999;
  padding: 10px;
  padding-bottom: 3.125rem;
  overflow: auto;
}
.page_top_view {
  display: flex;
  flex-direction: row;
  align-items: center;
}
.page_top_view div:nth-child(1) {
  display: flex;
  flex-direction: column;
}
.page_bottom_view {
  display: flex;
  flex-direction: row;
  align-items: center;
}
</style>
